package com.zbbt.sportslottery.ui.adapter;
import java.util.List;

import com.zbbt.sportslottery.R;
import com.zbbt.sportslottery.bean.ProtalOrders;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;

public class ElevenGridAdapter extends ArrayAdapter<Boolean> {

	private Context context;
	private CallBackEleven callBackeleven;
	private List<ProtalOrders> protals;

	public ElevenGridAdapter(Context context, Boolean[] objects, List<ProtalOrders> protals, CallBackEleven callBackeleven) {
		super(context, 0, objects);
		this.context = context;
		this.protals = protals;
		this.callBackeleven = callBackeleven;
	}
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.item_eleven_check, null);
			holder = new ViewHolder();
			convertView.setTag(holder);
			holder.checkBox = (CheckBox) convertView.findViewById(R.id.chkbox);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.checkBox.setText(protals.get(position).getProductName());
		holder.checkBox.setChecked(getItem(position));
		holder.checkBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
			public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
				callBackeleven.showChange(position,isChecked);
			}
		});
		return convertView;
	}

	class ViewHolder {
		CheckBox checkBox;
	}
	public interface CallBackEleven {
		/**
		 * 展示改变
		 */
	   public void showChange(int position,
				boolean isChecked);
	}
}
